using System;
using System.Web;
using System.Web.Caching;
namespace HKB.Common
{
	public class DataCache
	{
		private static string _webconfigfile = string.Empty;
		private static string _shopconfigfile = string.Empty;
		private static string _siteconfigfile = string.Empty;
		private static string _templateconfigfile = string.Empty;
		public static System.TimeSpan NoSlidingExpiration = Cache.NoSlidingExpiration;
		public static string webconfigfile
		{
			get
			{
				if (DataCache._webconfigfile == string.Empty)
				{
					DataCache._webconfigfile = HttpContext.Current.Server.MapPath("~/web.config");
				}
				return DataCache._webconfigfile;
			}
		}
		public static string shopconfigfile
		{
			get
			{
				if (DataCache._shopconfigfile == string.Empty)
				{
					DataCache._shopconfigfile = HttpContext.Current.Server.MapPath("~/App_Data/ShopConfig.config");
				}
				return DataCache._shopconfigfile;
			}
		}
		public static string siteconfigfile
		{
			get
			{
				if (DataCache._siteconfigfile == string.Empty)
				{
					DataCache._siteconfigfile = HttpContext.Current.Server.MapPath("~/App_Data/SiteConfig.config");
				}
				return DataCache._siteconfigfile;
			}
		}
		public static string templateconfigfile
		{
			get
			{
				if (DataCache._templateconfigfile == string.Empty)
				{
					DataCache._templateconfigfile = HttpContext.Current.Server.MapPath("~/App_Data/Template.config");
				}
				return DataCache._templateconfigfile;
			}
		}
		public static void DeleteCache(string CacheKey)
		{
			if (DataCache.GetCache(CacheKey) != null)
			{
				HttpRuntime.Cache.Remove(CacheKey);
			}
		}
		public static object GetCache(string CacheKey)
		{
			return HttpRuntime.Cache[CacheKey];
		}
		public static void SetCache(string CacheKey, object objObject)
		{
			DataCache.DeleteCache(CacheKey);
			HttpRuntime.Cache.Insert(CacheKey, objObject);
		}
		public static void SetCache(string CacheKey, object objObject, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration)
		{
			DataCache.DeleteCache(CacheKey);
            //bool flag = 0 == 0;
			HttpRuntime.Cache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
		}
		public static void SetCacheSecond(string CacheKey, object objObject, int seconds, System.TimeSpan slidingExpiration)
		{
			DataCache.DeleteCache(CacheKey);
			System.DateTime absoluteExpiration = System.DateTime.Now.AddSeconds((double)seconds);
            //bool flag = 0 == 0;
			HttpRuntime.Cache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
		}
		public static void SetCacheDepFile(string CacheKey, object objObject, string depfilename)
		{
			DataCache.DeleteCache(CacheKey);
			CacheDependency dependencies = new CacheDependency(depfilename);
			Cache cache = HttpRuntime.Cache;
			cache.Insert(CacheKey, objObject, dependencies, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
		}
	}
	public class DataCache<T>
	{
		public static T GetCache(string _key)
		{
			T result;
			if (HttpRuntime.Cache.Get(_key) != null)
			{
				result = (T)((object)HttpRuntime.Cache.Get(_key));
			}
			else
			{
				result = default(T);
			}
			return result;
		}
	}
}
